﻿using System;
using System.IO;
using System.Xml.Serialization;
using Xunit;

namespace Bookworm.Core.Tests
{
    public sealed class MiscTests
    {
        [Fact]
        public void Test()
        {
            var book = new EbookInfoXml();
            book.title = "Harry Potter";

            var serializer = new XmlSerializer(typeof(EbookInfoXml));
            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer, book);
                string xml = writer.ToString();
                Assert.NotNull(xml);
            }
        }

        [Fact]
        public void Test1()
        {
            var ebook = new EbookInfo();

            ebook.Title = "The Bourne Identity";
            ebook.Subtitles.Add("Another dizzily preposterous Ludlum comic-strip full of hyperventilating characters, pell-mell intrigue, and barbarous prose");
            ebook.Description = "He has no past. And he may have no future. His memory is blank. He only knows that he was flushed out of the Mediterranean Sea, his body riddled with bullets";
            ebook.Authors.Add("Robert Ludlum", AuthorType.Primary, null);
            ebook.Categories.Add(Category.LiteratureAndFiction);
            ebook.Tags.AddMany("Jason Bourne", "Bourne Identity", "Operation Medusa");
            ebook.Links.Add("http://www.amazon.com/Bourne-Identity-Robert-Ludlum/dp/0553199412/ref=sr_1_1/190-4339686-6116055?ie=UTF8&s=books&qid=1241896022&sr=1-1", LinkType.Review);
            ebook.Images.Add("path", ImageType.FrontCover, 200, 400);
            ebook.Format = Format.Pdf;
            ebook.Rating = EbookRating.Good;
            ebook.Isbn10 = "0553199412";
            ebook.Isbn13 = "9780553199413";
            ebook.Publisher = "Bantam Books";
            ebook.PublishDate = new DateTime(1980, 03, 01);
            ebook.Language = "en-US";
            ebook.PageCount = 535;

            var ebookxml = (EbookInfoXml)ebook;

            var serializer = new XmlSerializer(typeof(EbookInfoXml));
            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer, ebookxml);
                string xml = writer.ToString();
                Assert.NotNull(xml);
            }
        }

        [Fact]
        public void Test2()
        {
            var ebookContents = new EbookTocCollection();
            ebookContents.Add("Chapter 1","aaa",6);
            ebookContents.Add("Chapter 2", "bbb", 21);

            var ebookcontentxml = (EbookTocXml) ebookContents;

            var serializer = new XmlSerializer(typeof (EbookTocXml));
            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer,ebookcontentxml);
                string xml = writer.ToString();
                Assert.NotNull(xml);
            }
        }

        [Fact]
        public void TestSaveEbook()
        {
            using (var book = new Ebook())
            {
                book.Title = "Programming Windows Workflow Foundation";
                book.Subtitles.Add("Practical WF Techniques and Examples using XAML and C#");
                book.Subtitles.Add("A Concise and Practical Guide to Installation, Administration, and Customization");
                book.Authors.Add("K. Scott Allen", AuthorType.Primary,
                    "Scott Allen is a software architect with 14 years of experience in commercial " +
                    "software development. Scott has worked on platforms ranging from 8-bit embedded " +
                    "systems to highly scalable and distributed web applications. For the last six years " +
                    "Scott has concentrated on the .NET platform, and is a Microsoft MVP. Scott presents " +
                    "at loocal code camps and national conferences." + Environment.NewLine +
                    "Scott is a founder of the website OdeToCode.com, where he publishes articles and " +
                    "maintains a blog.");
                book.Categories.Add(Category.ComputersAndInternet);
                book.Tags.AddMany(".NET", "Microsoft", "WF");
                book.Format = Format.Pdf;
                book.Rating = EbookRating.Good;
                book.Isbn10 = "8184045298";
                book.Isbn13 = "9788184045291";
                book.Publisher = "Packt Publishing";
                book.PublishDate = new DateTime(2006, 12, 01);
                book.Language = "en-US";
                book.PageCount = 236;

                book.AddEntry(@"G:\Temp\ADO.NET in a nutshell.pdf");

                book.SaveAs(@"G:\Temp\ProgrammingWF.zip");
            }
        }

        [Fact]
        public void TestLoadMetadata()
        {
            Ebook book = new Ebook("G:/reading material/ProgrammingWF.zip");
        }
    }
}